<template>
  <div id="declare" style="height:100%;">

    <x-header v-if='pageType!="baoming"' slot="header" :left-options="{backText: ''}" style="width:100%;position:absolute;left:0;top:0;z-index:100;" :title="'删除报名'" >
      <a href="./#/racelist" style="font-size:24px" slot="right">
        <i class="fa fa-home fa-fw"></i>
      </a>

    </x-header>
    <Myheader v-if='pageType=="baoming"' :page="page"></Myheader>
    <!-- <x-header slot="header" :left-options="{backText: ''}" style="width:100%;position:absolute;left:0;top:0;z-index:100;" :title="'删除报名'">
          <a href="./#/racelist" style="font-size:24px" slot="right">
            <i class="fa fa-home fa-fw"></i>
          </a>

        </x-header> -->

    <card >
      <div slot="content" class="disclaimer_text content card-padding" v-text="content">

      </div>

      <div slot="footer">
        <group title="请确认您的证件号">
          <x-input title="证件号" placeholder="请输入您的证件号" placeholder-align="right" v-model="idnum2"></x-input>
        </group>
        <check-icon :value.sync="disclaimer" v-cloak>{{$t('disclaimer.agree')}}{{title}}</check-icon>

        <div class="button-wrapper">
          <x-button v-if="type=='del'" type="primary" :disabled="!disclaimer" text="确认" @click.native="del">确认
          </x-button>

          <x-button v-if="type=='refund'" type="primary" :disabled="!disclaimer" text="确认" @click.native="refund">确认
          </x-button>
        </div>
      </div>
    </card>

       <myFooter v-if='pageType!="baoming"' style="position: fixed;
    bottom: 0;width:100vw"></myFooter>

    <!--<view-box ref="viewBox">
      <div class="disclaimer_text content"
           v-text="content">
      </div>

      <group title="请确认您的证件号">
        <x-input title="证件号" placeholder="请输入您的证件号" placeholder-align="right" v-model="idnum2"></x-input>
      </group>


      <check-icon :value.sync="disclaimer" v-cloak>{{$t('disclaimer.agree')}}{{title}}</check-icon>
      <div class="button-wrapper">
        <x-button v-if="type=='del'" type="primary" :disabled="!disclaimer" text="确认"
                  @click.native="del">确认
        </x-button>
        <x-button v-if="type=='refund'" type="primary" :disabled="!disclaimer" text="确认"
                  @click.native="refund">确认
        </x-button>
      </div>

      <div v-transfer-dom>
        <previewer :list="list" ref="previewer" :options="options"></previewer>
      </div>


    </view-box>-->
  </div>
</template>


<script type="text/ecmascript-6">
/* eslint-disable*/
import Myheader from "@/common/components/myheader.vue";
import Myflow from "@/common/components/myflow.vue";
import myFooter from "@/common/components/myfooter.vue";
import {
  XHeader,
  CheckIcon,
  XButton,
  Previewer,
  TransferDom,
  ViewBox,
  XInput,
  Group,
  Card
} from "vux";

//统一的ajax组件
import qs from "qs";
import { axios } from "@/api/axios.js";
import { refund } from "@/api/refund.js";
import { indexedDB } from "@/api/indexedDB.js";
import mixin from "@/common/js/mixin";
export default {
  mixins: [mixin],
  props: ["page", "host"],
  directives: {
    TransferDom
  },
  data() {
    return {
      name: "",
      disclaimer: false,
      content:
        "申请退款后，本届活动将不再受理您的任何报名申请，您可以获得****元退款。如果您确认要退出，请在下方输入您的证件号并点击确定按钮",
      title: "",
      list: [],
      type: "",
      key: "",
      idnum: "",
      idnum2: "",
      amount: "",
      options: {
        getThumbBoundsFn(index) {
          // find thumbnail element
          let thumbnail = document.querySelectorAll(".impreviewer-demo-img")[
            index
          ];
          // get window scroll Y
          let pageYScroll =
            window.pageYOffset || document.documentElement.scrollTop;
          // optionally get horizontal scroll
          // get position of element relative to viewport
          //          console.log(thumbnail)
          let rect = thumbnail.getBoundingClientRect();
          // w = width
          return { x: rect.left, y: rect.top + pageYScroll, w: rect.width };
          // Good guide on how to get element coordinates:
          // http://javascript.info/tutorial/coordinates
        }
      }
    };
  },
  created() {
    let _this = this;
    //console.log('---')
    //console.log(this.$route.params.type)
    //console.log(this.$route.params.key)
    //console.log(this.$route.params.id)

    if (
      !this.$route.params.type ||
      !this.$route.params.key ||
      !this.$route.params.id
    ) {
      this.$router.push({ path: "message" });
    }

    this.key = this.$route.params.key;
    this.type = this.$route.params.type;
    this.idnum = this.$route.params.id;
    this.amount = this.$route.params.amount;

    if (this.type == "del") {
      this.content =
        "每个证件号（每名选手）至多可以删除一次报名，删除报名后，可以重新报名任何其它项目，您当前项目的报名资格将不再保留。";
    } else if (this.type == "refund") {
      this.content =
        "申请退款后，本届活动将不再受理您的任何报名申请,您可以获得" +
        this.amount +
        "元退款,如果您确认要退出，请在下方输入您的证件号并点击确定按钮";
    }
  },
  methods: {
    show(index) {
      this.$refs.previewer.show(index);
    },
    setProject: project => {
      indexedDB("project", "set", this.RACEID, project, function() {});
    },
    getState(state) {
      // 普通状态进行中 可以报名
      if (state === "normal") {
        return "进行中";
      }
    },
    del() {
      //删除
      let _this = this;
      if (this.idnum2 == "") {
        this.$vux.toast.show({
          type: "warn",
          text: this.$t("message.idnumbercannotbeempty")
        });
        return;
      }

      if (this.idnum !== this.idnum2) {
        this.$vux.toast.show({
          type: "warn",
          text: this.$t("message.idnumberisinconsistent")
        });
        return;
      }

      refund(`${window.host}registration/del`, {
        id: this.key,
        idnum: this.idnum2
      }).then(response => {
        if (response.data.code == "200") {
          this.$vux.toast.show({
            type: "success",
            text: "订单删除成功",
            onHide() {
              indexedDB(
                "IDNumber",
                "remove",
                this.RACEID,
                "",
                function(a) {}.bind(this)
              );
              _this.$router.push("/");
            }
          });
        } else {
          //console.log(response)
          this.$vux.toast.show({
            type: "warn",
            text: response.data.msg
          });
        }
      });
    },
    refund() {
      //退款
      let _this = this;
      if (this.idnum2 == "") {
        this.$vux.toast.show({
          type: "warn",
          text: this.$t("message.idnumbercannotbeempty")
        });
        return;
      }

      if (this.idnum !== this.idnum2) {
        this.$vux.toast.show({
          type: "warn",
          text: this.$t("message.idnumberisinconsistent")
        });
        return;
      }

      refund(`${window.host}refund/create`, {
        id: this.key,
        idnum: this.idnum2
      }).then(response => {
        if (response.data.code == "200") {
          this.$vux.toast.show({
            type: "success",
            text: this.$t("message.refundsuccessfully"),
            onHide() {
              _this.$router.push("/message");
            }
          });
        } else {
          //console.log(response)
          this.$vux.toast.show({
            type: "warn",
            text: response.data.msg
          });
        }
      });
    }
  },
  components: {
    myFooter,
    XHeader,
    Card,
    Myheader,
    Myflow,
    CheckIcon,
    XButton,
    Previewer,
    ViewBox,
    XInput,
    Group
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" rel="stylesheet/less">
#declare {
  position: relative;
}
.weui-tab {
  -webkit-overflow-scrolling: touch;
  position: relative;
}

#tabbar {
  position: fixed;
}
#tabbar .weui-tabbar {
  position: fixed;
}

#declare .disclaimer_text {
  padding-top: 25px;
  padding-bottom: 40px;
  padding-left: 10px;
  padding-right: 10px;
}

#declare .button.weui-btn,
button.weui-btn {
  margin-top: 10px;
}

#declare .button-wrapper {
  padding-left: 10px;
  padding-right: 10px;
  margin-bottom: 10px;
}

#declare .title {
  margin: 10px;
  width: auto;
}

#declare .title .top-title {
  font-weight: 400;
  font-size: 17px;
  width: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-wrap: normal;
  word-wrap: break-word;
  word-break: break-all;
}

#declare .weui-media-box__info {
  margin-top: 15px;
  padding-bottom: 5px;
  font-size: 13px;
  color: #745e5e;
  line-height: 1em;
  list-style: none;
  overflow: hidden;
}

.weui-media-box__info__meta_extra {
  padding-left: 1em;
  border-left: 1px solid #745e5e;
}

.weui-media-box__info__meta {
  float: left;
  padding-right: 1em;
}

#declare .content {
  margin-bottom: 20px;
}

#declare .content p {
  margin: 10px 0 10px;
  color: #666;
  font-size: 13px;
  line-height: 160%;
  // overflow: hidden;
  // text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  // -webkit-line-clamp: 2;
  // margin: 8px;
}

#declare .content span {
  color: #666;
  font-size: 13px;
  line-height: 160%;
}

#declare .content .imgs {
  width: 100%;
  // height: 100px;
  display: table-cell;
  vertical-align: middle;
  // text-align: center;
  padding: 10px;
}

#declare .content img {
  width: 100%;
}

#declare .weui-panel {
  margin-top: 0px;
}

#declare .vux-check-icon {
  line-height: 2;
  padding-left: 15px;
}

#app #declare .vux-check-icon > .weui-icon-success:before,
.vux-check-icon > .weui-icon-success-circle:before {
  color: #26a2ff;
}

#declare .vux-header .vux-header-title {
  font-size: 16px;
}

//h1标签
#declare .content {
  color: #666;
  box-sizing: border-box;
  h1 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 36px;
    margin-bottom: 10px;
  }
  h2 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 30px;
    margin-bottom: 10px;
  }
  h3 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 24px;
    margin-bottom: 10px;
  }
  h4 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 18px;
    margin-bottom: 10px;
  }
  h5 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 14px;
    margin-bottom: 10px;
  }
  h6 {
    font-weight: 500;
    line-height: 1.1;
    font-size: 12px;
    margin-bottom: 10px;
  }
  ol,
  ul {
    color: #666;
    display: block;
    list-style-type: decimal;
    -webkit-margin-before: 1em;
    -webkit-margin-after: 1em;
    -webkit-margin-start: 0px;
    -webkit-margin-end: 0px;
    -webkit-padding-start: 40px;
  }
  li {
    display: list-item;
    text-align: -webkit-match-parent;
  }
  button {
    display: inline-block;
    padding: 4px 12px;
    margin-bottom: 0;
    font-size: 14px;
    line-height: 20px;
    text-align: center;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.75);
    vertical-align: middle;
    cursor: pointer;
    background-image: linear-gradient(to bottom, #fff, #e6e6e6);
    background-repeat: repeat-x;
    border: 1px solid #ccc;
    border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
    border-bottom-color: #b3b3b3;
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),
      0 1px 2px rgba(0, 0, 0, 0.05);
    &:hover,
    &:focus {
      color: #333;
      text-decoration: none;
      background-position: 0 -15px;
      -webkit-transition: background-position 0.1s linear;
      -moz-transition: background-position 0.1s linear;
      -o-transition: background-position 0.1s linear;
      transition: background-position 0.1s linear;
    }
  }
  a {
    color: #666;
    text-decoration: none;
    line-height: 1.75;
    font-size: 14px;
    &:hover {
      color: #c81623;
    }
    strong {
      font-weight: 700;
    }
  }
}
</style>






